<html>
<head><meta charset="utf-8"><title>confused about EffectIndex::next_in_*_order · t-compiler/wg-mir-opt · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/index.html">t-compiler/wg-mir-opt</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/confused.20about.20EffectIndex.3A.3Anext_in_*_order.html">confused about EffectIndex::next_in_*_order</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="215263921"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/confused%20about%20EffectIndex%3A%3Anext_in_%2A_order/near/215263921" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/confused.20about.20EffectIndex.3A.3Anext_in_*_order.html#215263921">(Nov 01 2020 at 21:48)</a>:</h4>
<p>I was reading <a href="https://github.com/rust-lang/rust/blob/b2025326088b54fb3f083bebeba14e0a15bf00d3/compiler/rustc_mir/src/dataflow/framework/mod.rs"><code>rustc_mir::dataflow::framework</code></a> to try to get an understanding of how data-flow analysis is implemented in rustc, but this part confuses me:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">impl</span><span class="w"> </span><span class="n">EffectIndex</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">next_in_forward_order</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="k">match</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="n">effect</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="n">Effect</span>::<span class="n">Before</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">Effect</span>::<span class="n">Primary</span><span class="p">.</span><span class="n">at_index</span><span class="p">(</span><span class="bp">self</span><span class="p">.</span><span class="n">statement_index</span><span class="p">),</span><span class="w"></span>
<span class="w">            </span><span class="n">Effect</span>::<span class="n">Primary</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">Effect</span>::<span class="n">Before</span><span class="p">.</span><span class="n">at_index</span><span class="p">(</span><span class="bp">self</span><span class="p">.</span><span class="n">statement_index</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">),</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>


<span class="w">    </span><span class="k">fn</span> <span class="nf">next_in_backward_order</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="k">match</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="n">effect</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="n">Effect</span>::<span class="n">Before</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">Effect</span>::<span class="n">Primary</span><span class="p">.</span><span class="n">at_index</span><span class="p">(</span><span class="bp">self</span><span class="p">.</span><span class="n">statement_index</span><span class="p">),</span><span class="w"></span>
<span class="w">            </span><span class="n">Effect</span>::<span class="n">Primary</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">Effect</span>::<span class="n">Before</span><span class="p">.</span><span class="n">at_index</span><span class="p">(</span><span class="bp">self</span><span class="p">.</span><span class="n">statement_index</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="p">),</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>I understand <code>next_in_forward_order</code>:</p>
<ul>
<li>If you're before a certain statement, then the next effect is the primary effect at that statement</li>
<li>If you're at a certain statement, then the next effect is the before effect of the next statement</li>
</ul>
<p>But I don't understand <code>next_in_backward_order</code>. It looks to me like it's saying:</p>
<ul>
<li>If you're before a statement, then the next effect is the primary effect at that statement -- shouldn't the next effect be the primary at the previous?</li>
<li>If you're at a statement, then the next effect is the <em>before</em> effect of the previous statement -- shouldn't the next effect be the before of the <em>current</em> statement?</li>
</ul>
<p>What is it actually doing?</p>



<a name="216948046"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/confused%20about%20EffectIndex%3A%3Anext_in_%2A_order/near/216948046" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/confused.20about.20EffectIndex.3A.3Anext_in_*_order.html#216948046">(Nov 16 2020 at 23:34)</a>:</h4>
<p>Can someone explain this to me? Thank you so much!</p>



<a name="216976018"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/confused%20about%20EffectIndex%3A%3Anext_in_%2A_order/near/216976018" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/confused.20about.20EffectIndex.3A.3Anext_in_*_order.html#216976018">(Nov 17 2020 at 08:20)</a>:</h4>
<p>I suggest you activate tracing on a specific dataflow analysis and have a detailed look at what happens. Mabye the <code>statement_index</code> isn't the index of the current statement? I think you'll have to look at the callers of <code>next_in_backward_order</code></p>



<a name="217049224"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/confused%20about%20EffectIndex%3A%3Anext_in_%2A_order/near/217049224" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/confused.20about.20EffectIndex.3A.3Anext_in_*_order.html#217049224">(Nov 17 2020 at 19:19)</a>:</h4>
<p>Thank you for the suggestion! When you say 'tracing' do you mean something like <a href="https://rustc-dev-guide.rust-lang.org/mir/dataflow.html#graphviz-diagrams">https://rustc-dev-guide.rust-lang.org/mir/dataflow.html#graphviz-diagrams</a>?</p>



<a name="217049268"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/confused%20about%20EffectIndex%3A%3Anext_in_%2A_order/near/217049268" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/confused.20about.20EffectIndex.3A.3Anext_in_*_order.html#217049268">(Nov 17 2020 at 19:19)</a>:</h4>
<p>Or <code>RUSTC_LOG=rustc_mir::dataflow=trace</code>?</p>



<a name="217056503"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/confused%20about%20EffectIndex%3A%3Anext_in_%2A_order/near/217056503" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/confused.20about.20EffectIndex.3A.3Anext_in_*_order.html#217056503">(Nov 17 2020 at 20:16)</a>:</h4>
<p><code>RUSTC_LOG=rustc_mir::dataflow=info</code>. <code>=trace</code> can also be used, but unless you compile rustc yourself with all logging enabled, only info logs and higher are shown under any circumstances.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>